package shuffle;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:周次煜
 * Date: 2024-03-24
 * Time：15:30
 */
public class Cards {
   public String []colors={"♥","♣","♠","♦"};
    public List<Card> createCards() {
        List<Card> CardList= new  ArrayList<Card>();
        for (int i = 1; i <= 13; i++) {
            for (int j = 0; j < colors.length; j++) {
                Card card=new Card(i,colors[j]);
                CardList.add(card);
            }
        }

        return CardList;
    }


    public void shuffle(List<Card> CardList) {
        Random r=new Random();
        for (int j = CardList.size()-1; j > 0 ; j--) {
            int i=r.nextInt(j);
            swapCard(CardList,i,j);
        }

    }


    private void swapCard (List<Card> CardList,int i,int j) {

            Card tmp=CardList.get(i);
            CardList.set(i,CardList.get(j));
            CardList.set(j,tmp);

    }


    public List<Card> getCard(List<Card> CardList) {

        List<Card> hand=new ArrayList<>();

        Random r =new Random();


        for (int i = 0; i < 5; i++) {
                int j=r.nextInt(CardList.size());
                Card c=CardList.remove(j);
                hand.add(c);
                CardList.add(c);
        }

        return hand;

    }


//    public  void getCard(List<Card> CaedList) {
//
//        List<Card> hand1=new ArrayList<>();
//        List<Card> hand2=new ArrayList<>();
//        List<Card> hand3=new ArrayList<>();
//
//        List<List<Card>> hands=new ArrayList<>();
//        hands.add(hand1);
//        hands.add(hand2);
//        hands.add(hand3);
//
//        for (int i = 0; i < 5; i++) {
//            for (int j = 0; j < 3; j++) {
//
//                Card flg=CaedList.remove(0);
//               List<Card> hand =hands.get(j);
//               hand.add(flg);
//            }
//        }
//
//        System.out.println("========== 拿牌后 ==========");
//
//        System.out.println("第一个得到的牌："+hand1);
//        System.out.println("第二个得到的牌："+hand2);
//        System.out.println("第三个得到的牌："+hand3);
//
//    }


}
